<?php
/**
 * Created by PhpStorm.
 * User: CJJ
 * Date: 2017/8/28
 * Time: 15:41
 */
$Dir=explode('\\',dirname(__FILE__));$CDir=$Dir[0];for($i=1;$i<count($Dir)-3;$i++) $CDir.='/'.$Dir[$i];
require_once ('../../SQLBase.php');
class FinanceAdminManager{
    //获取财务人员信息
    function GetFinanceAdminInfo(){
        $db=new SQLBase();
        $queryStr='SELECT finance_admin.*,user.user_name FROM finance_admin,user WHERE user.user_ID=finance_admin.user_ID';
        $result=$db->queryData($queryStr);
        if(!$result){
            $resultArrayAll['state']=-1;
        }else{
            $resultArrayAll['state']=1;
            while ($temp=$result->fetch_assoc()){
                $resultArrayAll['data'][]=$temp;
            }
        }
        return $resultArrayAll;
    }

    //删除财务人员
    function FinanceAdminDeleteData($user_ID){
        $db = new SQLBase ();
        $queryStr = 'DELETE FROM finance_admin WHERE  user_ID=' . $user_ID . ';';
        $result = $db->queryData ( $queryStr );
        if (! $result) {
            $resultArrayAll ['state'] = - 1;
        } else {
            $resultArrayAll ['state'] = 1;
        }
        return $resultArrayAll;
    }

    function FinanceAddGetPageCount(){
        $db = new SQLBase ();
        $queryStr='SELECT count(*) FROM user WHERE user_state=1 AND user_ID NOT IN (SELECT user_ID FROM finance_admin);';//AND user_ID NOT IN (SELECT user_id FROM leader WHERE power_level=1)
        $result=$db->queryData($queryStr);
        if (! $result) {
            $resultArrayAll ['state'] = - 1;
        } else {
            $resultArrayAll ['state'] = 1;
            $temp=$result->fetch_assoc();
            $resultArrayAll ['pageCount'] = $temp['count(*)'];

        }
        return $resultArrayAll;
    }

    function FinanceAddGetUserLimit($n,$m){
        $db=new SQLBase();
        $queryStr="SELECT  user_ID,user_name  FROM user WHERE user_state=1 AND user_ID NOT IN (SELECT user_ID FROM finance_admin) LIMIT $n,$m";
//        echo $queryStr;
        $result=$db->queryData($queryStr);
        if(!$result){
            $resultArrayAll['state']=-1;
        }else{
            $resultArrayAll['state']=1;
            while ($temp=$result->fetch_assoc()){
                $resultArrayAll['data'][]=$temp;
            }
        }
        return $resultArrayAll;
    }
    function FinanceAddSearch($SearchText){
        $db = new SQLBase ();
        $queryStr="SELECT  user_ID,user_name  FROM user WHERE user_state=1 AND user_name LIKE '%%$SearchText%%' AND user_ID NOT IN (SELECT user_ID FROM finance_admin) ";
        $result=$db->queryData($queryStr);
        if (!$result) {
            $resultArrayAll ['state'] = - 1;
        } else {
            $resultArrayAll ['state'] = 1;
            while($temp=$result->fetch_assoc()){
                $resultArrayAll ['data'][] = $temp;
            }
        }
        return $resultArrayAll;
    }
    function FinanceAddInsert($data){
        $db = new SQLBase ();
        $queryStr = 'INSERT INTO finance_admin(user_ID,finance_power) VALUES('.$data['user_ID'].','.$data['finance_power'].');';
        $result=$db->queryData($queryStr);
        if(!$result){
            $resultArrayAll['state']=-1;
        }else{
            $resultArrayAll['state']=1;
        }
        return $resultArrayAll;
    }
    function FinanceAddUpdate($data){
        $db = new SQLBase ();
        $queryStr = 'UPDATE finance_admin SET finance_admin=' . $data ['finance_admin']  . ' WHERE user_ID='.$data['user_ID'].' ;';
        $result=$db->queryData($queryStr);
        if(!$result){
            $resultArrayAll['state']=-1;
        }else{
            $resultArrayAll['state']=1;
        }
        return $resultArrayAll;
    }

}